package com.blockchainenergy.common;

import com.blockchainenergy.blockChain.BlockChainService;
import com.blockchainenergy.blockChain.impl.BlockChainServiceImpl;
import net.sf.jsqlparser.statement.Block;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Arrays;

// 用于项目启动时运行方法
@Component
@Order(value = 1)
public class AfterRunner implements ApplicationRunner {
    @Resource
    private BlockChainService blockChainService;
    //    public static final String SAMPLE_XLSX_FILE_PATH = "/var/www/server/demo.xlsx";// 开发环境
    public static final String SAMPLE_XLSX_FILE_PATH = "src/main/resources/demo.xlsx";// 本地环境

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("执行方法");
        int[][] matrix = ExcelReader.copyData(SAMPLE_XLSX_FILE_PATH);
        for (int i = 0; i < 8; i++) blockChainService.matrixToBlock(matrix);
    }

    public static void main(String[] args) throws Exception {
        // 开始时间
        long stime = System.currentTimeMillis();
        int[][] matrix = ExcelReader.copyData(SAMPLE_XLSX_FILE_PATH);
        new BlockChainServiceImpl().matrixToBlock(matrix);
        // 结束时间
        long etime = System.currentTimeMillis();
        // 计算执行时间
        System.out.printf("执行时长：%d 毫秒.", (etime - stime));
    }
}
